﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using Module.EntitiesInfo;

namespace Module.DataAccess
{
	public class CMSLiveMatchDB
	{
		#region ConnectionString
        private string _connectionString;
        public string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }
        public CMSLiveMatchDB()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["localsql"].ToString();
        }
        #endregion

		#region Methods

		public virtual int Insert(CMSLiveMatchInfo cMSLiveMatchInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Title", cMSLiveMatchInfo.Title),
				new SqlParameter("@LinkLive", cMSLiveMatchInfo.LinkLive),
				new SqlParameter("@Avatar", cMSLiveMatchInfo.Avatar)
			};

			return (int) SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "CMS_LiveMatch_Insert", parameters);
		}

		public virtual void Update(CMSLiveMatchInfo cMSLiveMatchInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Id", cMSLiveMatchInfo.Id),
				new SqlParameter("@Title", cMSLiveMatchInfo.Title),
				new SqlParameter("@LinkLive", cMSLiveMatchInfo.LinkLive),
				new SqlParameter("@Avatar", cMSLiveMatchInfo.Avatar)
			};

			SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "CMS_LiveMatch_Update", parameters);
		}

	
		public virtual void Delete(int id)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Id", id)
			};

			SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "CMS_LiveMatch_Delete", parameters);
		}

        public IDataReader Select(int? type, string para_1, string para_2)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "CMS_LiveMatch_Select", type, para_1, para_2);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public IDataReader Select(int? type, string para_1)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "CMS_LiveMatch_Select", type, para_1);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public IDataReader Select(int? type)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "CMS_LiveMatch_Select", type);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Tính tổng số bản ghi
        /// </summary>
        /// <param name="keysearch">Từ khóa tìm kiếm</param>
      /// <param name="beginRow">Bản ghi đầu tiền</param>
        /// <param name="endRow">Bản ghi cuối</param>
        /// <returns></returns>
        public virtual int GetCount(string keysearch,int id,string linkLive,int beginRow, int endRow)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{                          
               new SqlParameter("@keysearch", keysearch),  
               new SqlParameter("@Id", id),
               new SqlParameter("@LinkLive", linkLive),  
               new SqlParameter("@IsTotalRow", 1)
			};

            return (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "CMS_LiveMatch_Search", parameters);
        }

        /// <summary>
        /// Tìm kiếm
        /// </summary>
        /// <param name="keysearch">Từ khóa tìm kiếm</param>
         // <param name="beginRow">Bản ghi đầu</param>
        /// <param name="endRow">Bản ghi cuối</param>
        /// <param name="orderByColumn">Sắp xếp</param>
        /// <returns></returns>
        public virtual DataTable Search(string keysearch,int id,string linkLive,int beginRow, int endRow, string orderByColumn)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{                
                new SqlParameter("@Keysearch", keysearch),  
               new SqlParameter("@Id", id),
               new SqlParameter("@LinkLive", linkLive),  
                new SqlParameter("@BeginRow", beginRow),
                new SqlParameter("@EndRow", endRow),
                new SqlParameter("@OrderByColumn", orderByColumn),
				new SqlParameter("@IsTotalRow", 0)
			};

            return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "CMS_LiveMatch_Search", parameters).Tables[0];
        }

      

		#endregion
	}
}
